#include <iostream>
#include <cstdio>
using namespace std;
struct node {
    int b;
    int e;
};
int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        int n, m, l, v, ans1 = 0;
        cin >> n >> m >> l >> v;
        int d[n + 5], v[n + 5], a[n + 5], p[m + 5];
        for (int i = 1; i <= n; i++) cin >> d[i] >> v[i] >> a[i];
        for (int i = 1; i <= m; i++) cin >> p[i];
        for (int i = 1; i <= n; i++) {
            if (a[i] >= 0 && v[i] + a[i] * (p[m] - d[i]) >= l) continue;
            int f = 0;
            for (int j = 1; j <= m; j++) {
                if (p[j] >= d[i]) {
                    f = j;
                    break;
                }
            }
            p[]
            if (a[i] > 0) {
                for (int j = f; j <= m; j++) {
                    if (v[i] + a[i] * (p[j] - d[i]) >= l) ans1++;

                }
            } else if (a[i] == 0) {

            }
        }
    }
    return 0;
}
